package com.tz.hotelmanager.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {

  @GetMapping("/")
  public String index(HttpServletRequest request, HttpSession session) {
    System.out.println((String) session.getAttribute("userbase") );
    JSONObject jsonObject = (String) session.getAttribute("userbase") == null ? null
        : JSONObject.parseObject((String) session.getAttribute("userbase"));
    if (jsonObject == null) {
      return "login";
    } else if (jsonObject.getString("type").equals("1")) {
      return "index";
    } else if (jsonObject.getString("type").equals("2")) {
      return "index2";
    } else if (jsonObject.getString("type").equals("3")) {
      return "index3";
    }
    return "login";
  }

  @GetMapping("/login")
  public String login() {
    return "login";
  }
}
